package com.ixiaowo.springcouldconsumermovie.feign;

import com.ixiaowo.springcouldconsumermovie.entity.User;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * feign  调用方式 demo
 *
 * fallback : 为hystrix的普通版本
 * fallBackFactory: 为hystrix增强版本
 */
@FeignClient(name = "microservice-provider-user",fallback = HystrixClientFallback.class/*,fallbackFactory = WithHystrixFactory.class*/)
public interface UserFeignClient {
    /**
     * 编写接口 添加调用方式  注意:两个坑 1.不支持@GetMapping()注解方式
 *                                        2.@PathVariable得设置value默认值
     * @param id
     * @return
     */
    @RequestMapping(value = "/simple/{id}",method = RequestMethod.GET)
    public User findById(@PathVariable("id") Long id);

}

/**
 * feign使用hystrix 普通版本
 */
@Component
 class HystrixClientFallback implements UserFeignClient {
     @Override
     public User findById(Long id) {
         User user = new User();
         user.setId(0L);
         return user;
     }
 }